import { Object3D, Vector2, Vector3, Vector4 } from "three/src/Three";
import Pixel from "../renderExtension/types/Pixel";
import { Point } from "../renderExtension/types/Point";
import { App } from "../Engine";
import DomUtils from "../utils/DomUtils";
import Helper from "../utils/Helper";
import Events from "../application/constants/Events";
import GPSUtils from "../utils/GPSUtils";
import GeoUtils from "../utils/GeoUtils";
import Const from "../application/constants/Const";
import Browser from "../utils/Browser";
import { TransformControls } from "three/examples/jsm/controls/TransformControls";
import Picker from "./Picker";

/** 鼠标操作事件 */
export default class Mouse {
    public app: App;
    private doMouseOverFn: any;
    private doMouseOutFn;
    private doMouseDownFn: any;
    private doMouseMoveFn: any;
    private doMouseUpFn: any;
    private doMouseWheelFn: any;
    private doKeyDownFn: any;
    private doKeyUpFn: any;
    private doTouchStartFn: any;
    private doTouchMoveFn: any;
    private doTouchEndFn: any;
    private doWindowResizeFn: any;
    private isMouseMove: boolean;
    private isRightDown: boolean;
    private isMouseDown: boolean;
    private isDragging: boolean;
    private isRotate: boolean;
    private oldPoint: Vector2;
    private clickTime: Date = new Date();
    private startDistance: number;
    private timer: any;
    private RaycasterType: Array<string>;
    private touchPoint: TouchEvent;
    private isScale: boolean;
    private touchMoveCount: number;
    private isDoubleTouch: boolean;
    private mouseState: string;
    private hoverObjects: Array<Object3D> = new Array<Object3D>(); //鼠标悬停的物体
    private selectControl: Picker;
    public dragPointInCamera: Point; //鼠标拖动时，得到的地图位置
    public mouseDownPoint:Point; //鼠标按下时，得到的地图位置
    public pixelMouse: Pixel; //鼠标在屏幕上的像素位置

    constructor() {
        this.app = App.getInstance();
        this.selectControl = Picker.getInstance();
        this.initAttributes();
        this.initComponent();
    }
    /** 添加事件获取射线交点功能 */
    public addRaycasterType(type: string) {
        let index = this.RaycasterType.indexOf(type);
        if (index < 0) { //避免重复添加
            this.RaycasterType.push(type);
        }
    }
    /** 移除事件获取射线交点功能 */
    public removeRaycasterType(type: string) {
        let index = this.RaycasterType.indexOf(type);
        if (index >= 0) {
            this.RaycasterType.splice(index, 1);
        }
    }

    /**
     * 添加鼠标悬停的对象
     * @param object 鼠标经过该物体会悬停
     */
    public addHoverObject(object: Object3D) {
        let index = this.hoverObjects.indexOf(object);
        if (index == -1) {
            this.hoverObjects.push(object);
        }
        
        if(this.RaycasterType.indexOf(Events.MouseHover) == -1){
            this.addRaycasterType(Events.MouseHover);
        }
    }

    /**
     * 删除鼠标悬停的对象
     * @param object
     */
    public removeHoverObject(object: Object3D) {
        let index = this.hoverObjects.indexOf(object);
        if (index >= 0) {
            this.hoverObjects.splice(index, 1);

            if(this.RaycasterType.indexOf(Events.MouseHover) == -1){
                this.removeRaycasterType(Events.MouseHover);
            }
        }
    }

    /** 获取鼠标各类坐标 */
    public getMouseEvent(e: MouseEvent | MouseEvent | TouchEvent, type: string, optionObject?: Object3D[]) {
        let domElement = document.getElementById(this.app.div)
        let offSet = DomUtils.getOffsetByBody(domElement);
        let pixel = DomUtils.getContainerPixel(e, offSet.left, offSet.top);
        this.pixelMouse = pixel;

        let pickParam = {pixel: pixel, optionObjects: optionObject, isIntersectCarpet: true};
        if (this.RaycasterType.indexOf(type) >= 0 || optionObject) {
            // if(type == Events.MouseDown || type == Events.MouseMove || optionObject){
                pickParam.isIntersectCarpet = false;
            // }
            // let select: any = this.selectControl.getPickPoint(pickParam);
            // return new InteractionEvent(e.target, select.lnglat, pixel, type, e['deltaY'], e['button'], select.intersectObj, select.carpetLnglat);
        } else {
            // let event = new InteractionEvent(e.target, GeoUtils.containerToLngLat(pixel), pixel, type, e['deltaY'], e['button'], undefined);
            // return event;
            pickParam.isIntersectCarpet = true;
        }

        let select: any = this.selectControl.getPickPoint(pickParam);
        return new InteractionEvent(e.target, select.lnglat, pixel, type, e['deltaY'], e['button'], select.intersectObj, select.carpetLnglat);
    }
    private downEvent;
    /** 鼠标按下 */
    private mouseDown(e: MouseEvent) {
        // let domElement = document.getElementById(this.app.div)
        if (this.timer != undefined) {
            window.clearTimeout(this.timer);
            this.timer = undefined;
        }
        this.downEvent = this.getMouseEvent(e, Events.MouseDown);
        this.setDownPoint(this.downEvent);
        
        this.oldPoint = new Vector2(e.clientX, e.clientY);
        this.app.fireEvent(Events.MouseDown, this.downEvent);
        // domElement.removeEventListener('mousemove', this.doMouseMoveFn);
        // document.addEventListener('mousemove', this.doMouseMoveFn, false);

        // document.addEventListener('mouseup', this.doMouseUpFn, false);
        this.app.camera.cameraUtils.isCollisionEye = false;
        
        this.isRightDown = (e.button == 2);
        this.isMouseDown = true;
        this.isMouseMove = false;
    }

    private setDownPoint(downEvent){//设置鼠标按下的点
        if(downEvent && downEvent.lnglat){
            let lngLat:Point = downEvent.lnglat.clone();
            let webmocPoint:Point = lngLat.toEPSGWeb();
            this.mouseDownPoint = webmocPoint.clone();
            this.app.map.mapVirtualCarpet.adjustZ(webmocPoint.z);
        }else{
            this.mouseDownPoint = null;
            this.app.map.mapVirtualCarpet.adjustZ(0);
        }
    }

    private setDragPointInCamera(point: Point){//设置鼠标拖拽的点的相机坐标
        this.dragPointInCamera = point;
    }
    
    private lastWheelPixel: Pixel;
    /**
     * 鼠标滚动前，记录鼠标在地图上的点
     * @param e 鼠标事件
     */
    public setCameraBeforeWheel(e){
        let curPixel = e.pixel;
        if(!curPixel){
            return;
        }
        let pickParam = {pixel: curPixel, isIntersectCarpet: true};
        let maxOffsetX = this.app.three.domElement.clientWidth / 100;
        let maxOffsetY = this.app.three.domElement.clientHeight / 100;
        if(!this.lastWheelPixel || (Math.abs(curPixel.x - this.lastWheelPixel.x) > maxOffsetX || Math.abs(curPixel.y - this.lastWheelPixel.y) > maxOffsetY)){
            pickParam.isIntersectCarpet = false;
        }
        let intersectData = Picker.getInstance().getPickPoint(pickParam);
        this.app.mouse.setDownPoint(intersectData);

        this.lastWheelPixel = e.pixel;
    }

    /**
     * 鼠标滚动后，设置相机的位置，使鼠标还在之前的位置上
     * @param e 鼠标事件
     */
    public setCameraAfterWheel(e: InteractionEvent){
        this.app.three.camera.updateMatrix();
        this.app.three.camera.updateMatrixWorld();
        
        let pickParam = {pixel: e.pixel, isIntersectCarpet: true};
        let intersectData = Picker.getInstance().getPickPoint(pickParam);
        let lngLat:Point = intersectData.carpetLnglat.clone();
        let webmocPoint:Point = lngLat.toEPSGWeb();
        let cameraMatrix = this.app.three.camera.matrixWorldInverse;

        let cameraPoint = webmocPoint.applyMatrix4(cameraMatrix);
        this.dragPointInCamera = new Point(cameraPoint.x, cameraPoint.y, cameraPoint.z, Const.EPSGType.EPSGWeb);

        let draggingEvent = {pixel: e.pixel};
        let isUpdateZ = true;
        this.app.camera.orbit.setCameraOffset(draggingEvent, isUpdateZ);
        this.app.mouse.setDownPoint(null);
        this.dragPointInCamera = null;
    }

    private lastHoverObj;
    private handleMouseHover(e: MouseEvent) {
        if(this.hoverObjects.length > 0){
            let hoverEvent = this.getMouseEvent(e, Events.MouseHover, this.hoverObjects);
            if( (hoverEvent.object && this.mouseState != Events.MouseHover) ||
                 (hoverEvent.object && hoverEvent.object!=this.lastHoverObj && this.mouseState == Events.MouseHover) ){
                this.app.fireEvent(Events.MouseHover, hoverEvent);
                this.mouseState = Events.MouseHover;

                //把鼠标样式变成手型
                let domElement = document.getElementById(this.app.div);
                domElement.style.cursor = 'pointer';

                this.lastHoverObj = hoverEvent.object;
            }else if(!hoverEvent.object && this.mouseState == Events.MouseHover){
                this.app.fireEvent(Events.MouseUnHover);
                this.mouseState = Events.MouseMove;

                //把鼠标样式变成默认 
                let domElement = document.getElementById(this.app.div)
                domElement.style.cursor = 'default';
            }
            
        }else if(this.mouseState == Events.MouseHover){
            //把鼠标样式变成默认 
            let domElement = document.getElementById(this.app.div)
            domElement.style.cursor = 'default';
        }
    }

    /** 鼠标移动 */
    private mouseMove(e: MouseEvent) {
        if (!this.isMouseDown) {
            let moveEvent = this.getMouseEvent(e, Events.MouseMove);
            this.app.fireEvent(Events.MouseMove, moveEvent);

            this.handleMouseHover(e);
            return;
        }
        let screenPoint: Vector2 = new Vector2(e.clientX, e.clientY);
        if (this.oldPoint) {
            this.isMouseMove = !Helper.vector2Equals(this.oldPoint, screenPoint);
        }
        if (!this.isMouseMove) return;
        if (this.isRightDown) {
            this.isRotate = true;
            if (this.app.options.Scene.rotateEnable) {//旋转开关
                let rotateEvent = this.getMouseEvent(e, Events.MapRotate);
                this.app.fireEvent(Events.MapRotate, rotateEvent);
            }
        } else {
            if (this.app.options.Scene.dragEnable) {//拖动标识 
                if (!this.isDragging) {
                    let dragStartEvent = this.getMouseEvent(e, Events.MapDragStart);
                    this.app.fireEvent(Events.MapDragStart, dragStartEvent);
                    this.isDragging = true;
                }
                
                this.app.three.camera.updateMatrix();
                this.app.three.camera.updateMatrixWorld();

                let draggingEvent = this.getMouseEvent(e, Events.MapDragging); //this.getMoveEvent(e);
                this.setMovePoint(draggingEvent);

                this.app.fireEvent(Events.MapDragging, draggingEvent);//drag处理类触发dragend事件
            }
        }
    }

    private getMoveEvent(e){
        let optionObjects = [];
        for(let i=0; i<this.app.three.scene.children.length; i++){
            let obj = this.app.three.scene.children[i];
            if (obj['canNotSelect']) { //true表示该图层不参与射线拾取，false表示图层参与射线拾取
                continue;
            }
            if(obj instanceof TransformControls){ //控制器中的mesh不参与射线拾取
                continue;
            }

            optionObjects.push(obj);
        }
        let draggingEvent = this.getMouseEvent(e, Events.MapDragging, optionObjects); //, [this.app.three.scene]
        return draggingEvent;
    }

    private setMovePoint(draggingEvent: InteractionEvent){
        if(draggingEvent && draggingEvent.carpetLnglat){
            let lngLat:Point = draggingEvent.carpetLnglat.clone();
            let webmocPoint:Point = lngLat.toEPSGWeb();

            let cameraMatrix = this.app.three.camera.matrixWorldInverse;
            let cameraPoint = webmocPoint.applyMatrix4(cameraMatrix);

            let dragPointInCamera = new Point(cameraPoint.x, cameraPoint.y, cameraPoint.z, Const.EPSGType.EPSGWeb);
            this.app.mouse.setDragPointInCamera(dragPointInCamera);
        }else{
            this.app.mouse.setDragPointInCamera(null);
        }
       
    }
    /** 鼠标弹起 */
    private mouseUp(e: MouseEvent) {
        if (this.timer != undefined) {
            window.clearTimeout(this.timer);
            this.timer = undefined;
        }
        this.setDownPoint(null);
        this.setMovePoint(null);

        this.app.fireEvent(Events.MouseUp, e);
        let isOnCanvas = false; //当前的鼠标是否还在地图的canvas上
        if(Browser.gecko){ //火狐浏览器
            isOnCanvas = (e['explicitOriginalTarget'].id == Const.MapConst.mapCanvasID);
        }else{
            isOnCanvas = (e['toElement'].id == Const.MapConst.mapCanvasID);
        }
        if(isOnCanvas){
            if (this.isRightDown) {//右键
                if (!this.isRotate) {
                    if (new Date().getTime() - this.clickTime.getTime() < 300) {
                        // let rightDBevent = this.getMouseEvent(e, Events.RightDoubleClick);
                        this.app.fireEvent(Events.RightDoubleClick, this.downEvent);//用于pc端缩放
                    } else {
                        // let rightEvent = this.getMouseEvent(e, Events.RightClick);
                        this.app.fireEvent(Events.RightClick, this.downEvent);
                    }
                }else{
                    let rotateEvent = this.getMouseEvent(e, Events.MapRotate);
                    this.app.fireEvent(Events.MapRotateEnd, rotateEvent);
                }
            } else {//左键
                if (!this.isMouseMove) {
                    if (new Date().getTime() - this.clickTime.getTime() < 300) {
                        // let dblEvent = this.getMouseEvent(e, Events.DoubleClick);
                        this.app.fireEvent(Events.DoubleClick, this.downEvent);
                    } else {
                        // let clickEvent = this.getMouseEvent(e, Events.Click);
                        if (this.app.options.Scene.isOpenMapClick) {
                            this.app.fireEvent(Events.Click, this.downEvent);
                        }
                    }
                }
            }
        }

        this.clickTime = new Date();
        this.isMouseDown = false;
        this.isRotate = false;
        if(this.isDragging){
            this.app.fireEvent(Events.MapDragEnd);
        }
        this.isDragging = false;
        this.app.camera.cameraUtils.isCollisionEye = false;
        // let domElement = document.getElementById(this.app.div)
        // domElement.addEventListener('mousemove', this.doMouseMoveFn, false);
        // document.removeEventListener('mousemove', this.doMouseMoveFn);

        // document.removeEventListener('mouseup', this.doMouseUpFn);
    }

    /** 鼠标滚轮滚动 */
    private mouseWheel(e: MouseEvent) {
        if (this.app.options.Scene.zoomEnable) {//滚轮缩放
            let wheelEvent = this.getMouseEvent(e, Events.MouseWheel);
            this.app.fireEvent(Events.MouseWheel, wheelEvent);
        }
    }
    /** 键盘按钮按下 */
    private keyDown(e: KeyboardEvent) {
        this.app.fireEvent(Events.KeyDown, e);
    }
    /** 键盘按钮弹起 */
    private keyUp(e: KeyboardEvent) {
        this.app.fireEvent(Events.KeyUp, e);
    }
    protected doMouseOver(e: KeyboardEvent) {
        this.app.fireEvent(Events.MouseOver, e);
    }
    protected doMouseOut(e: KeyboardEvent) {
        this.app.fireEvent(Events.MouseOut, e);
    }
    private touchStart(e: TouchEvent) {
        this.touchPoint = e;
        if (this.timer != undefined) {
            window.clearTimeout(this.timer);
            this.timer = undefined;
        }

        let touchCount = e.targetTouches.length;
        this.isRightDown = false;
        this.isMouseMove = false;
        this.isMouseDown = true;
        // this.clickTime = new Date();
        if (touchCount == 2) {
            let v1 = new Vector2(e.touches[0].clientX, e.touches[0].clientY);
            let v2 = new Vector2(e.touches[1].clientX, e.touches[1].clientY);
            this.startDistance = v1.distanceTo(v2);
            this.isScale = false;
            this.isRotate = false;
            this.touchMoveCount = 0;
            this.isDoubleTouch = true;

            let downEvent = this.getMouseEvent(e, Events.MouseDown);
            downEvent['button'] = 2;//表示旋转
            this.app.fireEvent(Events.MouseDown, downEvent)
        } else if (touchCount == 1) {
            let downEvent = this.getMouseEvent(e, Events.MouseDown);
            downEvent['button'] = 0; //表示移动
            this.app.fireEvent(Events.MouseDown, downEvent, touchCount);
            if (this.app.options.Scene.isOpenMapClick) {
                this.app.fireEvent(Events.Click, downEvent);
            }
            this.isDoubleTouch = false;
        }
    }

    private touchMove(e: TouchEvent) {
        this.touchPoint = e;
        if (this.timer != undefined) {
            window.clearTimeout(this.timer);
            this.timer = undefined;
        }

        let touchCount = e.targetTouches.length;
        if (!this.isMouseDown) return;
        if (touchCount == 1 && !this.isDoubleTouch) {//移动
            this.isMouseMove = true;

            let moveEvent = this.getMouseEvent(e, Events.MouseMove);
            this.app.fireEvent(Events.MouseMove, moveEvent, touchCount);

            moveEvent.type = Events.MapDragging;
            this.app.fireEvent(Events.MapDragging, moveEvent);
        } else if (touchCount == 2) {//缩放、旋转
            this.isDoubleTouch = true;
            let pt1 = new Vector2(e.touches[0].clientX, e.touches[0].clientY);
            let pt2 = new Vector2(e.touches[1].clientX, e.touches[1].clientY);
            let currentDistance = pt1.distanceTo(pt2);

            let moveCount = 5;
            let moveDistance = 15;
            //这里的思路是根据第一次移动时双指的距离，和第5次次移动时双指的距离之间的差大于15，就认为是缩放
            if (this.touchMoveCount <= moveCount) {
                this.touchMoveCount++;
                if (this.touchMoveCount > moveCount) {
                    let subDistance = Math.abs(this.startDistance - currentDistance);
                    if (subDistance > moveDistance) {
                        this.isScale = true;
                        this.isRotate = false;
                    } else {
                        let rotateAngle = 60;
                        let angle = Math.abs((Math.atan2(pt1.y - pt2.y, pt1.x - pt2.x) * 180) / Math.PI);
                        let isNeedRotate = (angle <= rotateAngle || Math.abs(180 - angle) <= rotateAngle);
                        if (isNeedRotate) {
                            this.isRotate = true;
                            this.isScale = false;
                        }
                    }
                }
                return;
            }

            if (this.isScale) {//缩放
                if (!this.app.options.Sce.touchZoom) return;//缩放开关
                this.app.fireEvent(Events.ZoomChange, this.startDistance / currentDistance);
            }
            if (this.isRotate) {//旋转
                if (!this.app.options.Scene.rotateEnable) return;//旋转开关
                let rotateEvent = this.getMouseEvent(e, Events.MapRotate);
                e['button'] = 2;//表示旋转
                this.app.fireEvent(Events.MapRotate, rotateEvent);
            }
        }
    }
    private touchEnd(e: TouchEvent) {
        if (this.timer != undefined) {
            window.clearTimeout(this.timer);
            this.timer = undefined;
        }

        let touchCount = this.touchPoint.targetTouches.length;
        // if(e.targetTouches.length == 1){
        // }
        this.app.fireEvent(Events.MouseUp, this.touchPoint, touchCount);
        this.app.fireEvent(Events.TouchEnd, this.touchPoint);

        this.startDistance = null;
        if (this.isMouseMove || this.isRotate || this.isScale) {//拖动，旋转，缩放
            if (new Date().getTime() - this.clickTime.getTime() > 500) {
                let rightEvent = this.getMouseEvent(this.touchPoint, Events.RightClick);
                this.app.fireEvent(Events.RightClick, rightEvent);
            } else {
                if (touchCount == 1) {
                    let clickEvent = this.getMouseEvent(this.touchPoint, Events.Click);
                    if (this.app.options.Scene.isOpenMapClick) {
                        this.app.fireEvent(Events.Click, clickEvent);
                    }

                    if (new Date().getTime() - this.clickTime.getTime() < 300) {
                        this.app.fireEvent(Events.DoubleClick, clickEvent);
                    }
                }
                //  else if (touchCount == 2) {
                // let touchDBevent = await this.getMouseEvent(this.touchPoint, Events.Map.touchDBlClick);
                // this.map.fireEvent(Events.Map.touchDBlClick, touchDBevent);//用于pad端缩放
                // }
            }
        }
        this.isMouseDown = false;
        this.isRotate = false;
        this.touchMoveCount = 0;
        this.isDoubleTouch = false;
        this.isScale = false;
        this.clickTime = new Date();
    }
    private windowResize() {
        this.app.fireEvent(Events.Resize);
    }
    private initMouseEvents() {
        let domElement = document.getElementById(this.app.div);
        if (!Helper.isPC()) return;
        if (this.app.options.Scene.resizeEnable) {
            window.addEventListener('resize', this.doWindowResizeFn, false);
        }

        domElement.addEventListener('mousedown', this.doMouseDownFn, false);
        domElement.addEventListener('mousemove', this.doMouseMoveFn, false);
        window.addEventListener('mouseup', this.doMouseUpFn, false);
        domElement.addEventListener('wheel', this.doMouseWheelFn, false);
        domElement.addEventListener("mouseover", this.doMouseOverFn, false);
        domElement.addEventListener("mouseout", this.doMouseOutFn, false);
        window.addEventListener('keydown', this.doKeyDownFn, false);
        window.addEventListener('keyup', this.doKeyUpFn, false);
    }
    private initTouchEvents() {
        let domElement = document.getElementById(this.app.div);
        if (Helper.isPC()) return;
        domElement.addEventListener('touchstart', this.doTouchStartFn, false);
        domElement.addEventListener('touchmove', this.doTouchMoveFn, false);
        domElement.addEventListener('touchend', this.doTouchEndFn, false);
    }
    public dispose() {
        let domElement = document.getElementById(this.app.div);
        domElement.removeEventListener('mousedown', this.doMouseDownFn);
        domElement.removeEventListener('mousemove', this.doMouseMoveFn);
        window.removeEventListener('mouseup', this.doMouseUpFn);
        domElement.removeEventListener('wheel', this.doMouseWheelFn);
        domElement.removeEventListener("mouseover", this.doMouseOverFn);
        domElement.removeEventListener("mouseout", this.doMouseOutFn);
        window.removeEventListener('keydown', this.doKeyDownFn);
        window.removeEventListener('keyup', this.doKeyUpFn);
        domElement.removeEventListener('touchstart', this.doTouchStartFn);
        domElement.removeEventListener('touchmove', this.doTouchMoveFn);
        domElement.removeEventListener('touchend', this.doTouchEndFn);
    }

    protected initAttributes() {
        // this.RaycasterType = [Events.RightDoubleClick, Events.RightClick, Events.DoubleClick, Events.Click, Events.MouseDown, Events.MapDragging];
        this.RaycasterType = [Events.MouseDown];
        if (!Helper.isPC()) { //移动端
            this.RaycasterType.push(Events.MouseDown);
        }
        if (this.app) {
            if (this.app.options.Scene.around !== 'center')
                this.addRaycasterType(Events.MouseWheel);
        }
    }
    protected initComponent() {
        this.doMouseOverFn = this.doMouseOver.bind(this);
        this.doMouseOutFn = this.doMouseOut.bind(this);
        this.doMouseDownFn = this.mouseDown.bind(this);
        this.doMouseMoveFn = this.mouseMove.bind(this);
        this.doMouseUpFn = this.mouseUp.bind(this);
        this.doMouseWheelFn = this.mouseWheel.bind(this);
        this.doKeyDownFn = this.keyDown.bind(this);
        this.doKeyUpFn = this.keyUp.bind(this);
        this.doTouchStartFn = this.touchStart.bind(this);
        this.doTouchMoveFn = this.touchMove.bind(this);
        this.doTouchEndFn = this.touchEnd.bind(this);
        this.doWindowResizeFn = this.windowResize.bind(this);
        this.initMouseEvents();
        this.initTouchEvents();
        this.app.on(Events.Dispose, this.dispose, this);
        this.app.three.domElement.addEventListener('contextmenu', (e) => { DomUtils.stopEvents(e) })
        this.app.on(Events.Click, this.clickEvent.bind(this), this);
    }

    private clickEvent(e: InteractionEvent) {
        if(!e){
            return;
        }
        let curObj = e.object;
        while (curObj) {
            if (curObj['setClick'] && !curObj['canNotSelect']) {
                let isHandle = curObj['setClick'](e);
                if(isHandle){
                    return;
                }
            }
            curObj = curObj.parent;
        }
    }
}

class InteractionEvent {
    public target: any;
    public lnglat: Point;
    public carpetLnglat: Point;
    public pixel: Pixel;
    public type: string;
    public deltaY: number;
    public button: number;
    public objs: any;
    public object: any;
    constructor(tgt: any, lnglat: Point, px: Pixel, type: string, deltaY: number, btn: number, objs: any, carpetLnglat: Point=null) {
        this.target = tgt;
        this.lnglat = lnglat;
        this.pixel = px;
        this.type = type;
        this.deltaY = deltaY;
        this.button = btn || 0;
        this.objs = objs;
        if (objs){
            this.object = objs.object;
        }

        if(!carpetLnglat){
            this.carpetLnglat = this.lnglat.clone();
        }else{
            this.carpetLnglat = carpetLnglat;
        }
           
    }
}
export { InteractionEvent }
